import { cloudDBZone, initCloudDB } from '@/AGC/manager'
import { CloudDBZoneQuery } from '@hw-agconnect/database'
import { FoodDislike } from '@/AGC/model/FoodDislike'
import { ExerciseDislike } from '@/AGC/model/ExerciseDislike'

/**
 * 查询用户不喜欢的运动
 * @param user_id 用户id
 * @returns 用户不喜欢的运动
 */
export const queryExerciseDislike = async (user_id: number) => {
  if (!cloudDBZone) await initCloudDB()

  const query = CloudDBZoneQuery.where(ExerciseDislike)
  query.equalTo('user_id', user_id)
  const snapshot = await cloudDBZone.executeQuery(query)
  return snapshot.getSnapshotObjects()
}

/**
 * 查询用户不喜欢的食物
 * @param user_id 用户id
 * @returns 用户不喜欢的食物
 */
export const queryFoodDislike = async (user_id: number) => {
  if (!cloudDBZone) await initCloudDB()

  const query = CloudDBZoneQuery.where(FoodDislike)
  query.equalTo('user_id', user_id)
  const snapshot = await cloudDBZone.executeQuery(query)
  return snapshot.getSnapshotObjects()
}

/**
 * 执行用户不喜欢的食物插入
 * @param foodDislike 用户不喜欢的食物
 */
export const executeUpsertFoodDislike = async (foodDislike: FoodDislike) => {
  if (!cloudDBZone) await initCloudDB()

  const cloudDBResult = await cloudDBZone.executeUpsert(foodDislike)
  console.log('executeUpsertFoodDislike: ', cloudDBResult)
}

/**
 * 执行用户不喜欢的运动插入
 * @param exerciseDislike 用户不喜欢的运动
 */
export const executeUpsertExerciseDislike = async (exerciseDislike: ExerciseDislike) => {
  if (!cloudDBZone) await initCloudDB()

  const cloudDBResult = await cloudDBZone.executeUpsert(exerciseDislike)
  console.log('executeUpsertExerciseDislike: ', cloudDBResult)
}

/**
 * 执行用户不喜欢的食物删除
 * @param list 用户不喜欢的食物列表
 */
export const executeDeleteFoodDislike = async (list: FoodDislike[]) => {
  if (!cloudDBZone) await initCloudDB()

  const cloudDBResult = await cloudDBZone.executeDelete(list)
  console.log('executeDeleteFoodDislike: ', cloudDBResult)
}

/**
 * 执行用户不喜欢的运动删除
 * @param list 用户不喜欢的运动列表
 */
export const executeDeleteExerciseDislike = async (list: ExerciseDislike[]) => {
  if (!cloudDBZone) await initCloudDB()

  const cloudDBResult = await cloudDBZone.executeDelete(list)
  console.log('executeDeleteExerciseDislike: ', cloudDBResult)
}
